<?php

namespace App\Http\Controllers;

use App\Common\SwooleTableTest;
use App\Jobs\TestRabitmq;
use Illuminate\Http\Request;

class ApiController extends Controller
{
    public function rpc()
    {
        phpinfo();
//        dispatch((new TestRabitmq(3,'test2'))->onConnection('rabbitmq')->onQueue('sync-db'));
//        echo 123565664;
//        $server = new Server();
//        $server->getProcedureHandler()
//            ->withCallback('addition', function ($a, $b) {
//                return $a + $b;
//            })
//            ->withCallback('random', function ($start, $end) {
//                return mt_rand($start, $end);
//            })
//        ;
//
//        echo $server->execute();
    }

    public function testSwoole()
    {
        $swoolTable = new SwooleTableTest();

        return $swoolTable->test();
    }

    public function testGo()
    {
        $c = 10;
        while($c--) {
            go(function () {
                //这里使用 sleep 5 来模拟一个很长的命令
                var_dump(co::exec("sleep 5"));
            });
        }
    }
//    public function doSomething($arg1, $arg2 = 3)
//    {
//        return $arg1 + $arg2;
//    }
//
//    public function rpc()
//    {
//        $server = new Server();
//        $procedureHandler = $server->getProcedureHandler();
//
//// Bind the method Api::doSomething() to the procedure myProcedure
////        $procedureHandler->withClassAndMethod('myProcedure', 'ApiController', 'doSomething');
//
//// Use a class instance instead of the class name
//        $procedureHandler->withClassAndMethod('mySecondProcedure', new ApiController, 'doSomething');
//        // The procedure and the method are the same
////        $procedureHandler->withClassAndMethod('doSomething', 'ApiController');
//
//        $procedureHandler->withObject(new ApiController());
//        echo $server->execute();
//    }
}
